import 'package:flutter/material.dart';

class RouterApp extends StatelessWidget
{
      @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
              home: HomePage(),
              title: 'MaterialApp 示例',
              routes:{
                      '/first':(BuildContext context)=>FirstPage(),//添加路由
                      '/second':(BuildContext context)=>SecondPage(),
              },
              initialRoute: '/first',//初始路由页面为first页面
    );
  }
}


//这是一个可改变的widget
class HomePage extends StatefulWidget
{
  @override
  _HomePageState createState() {
    // TODO: implement createState
    return _HomePageState();
  }
}

class _HomePageState extends State<HomePage>
{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: AppBar(
        title: Text('MaterialApp 示例') ,

      ),
      body: new Center(
        child: Text('主页'),
      ),
    );
  }
}
//第一个路由页面

class FirstPage extends StatelessWidget
{
      @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
                appBar: AppBar(
                        title: Text('第一页'),
                ),
                body: Center(
                        child: RaisedButton(onPressed: ()
                        {
                              Navigator.pushNamed(context, '/second');
                        },
                        child: Text('这是第一页',style: TextStyle(fontSize: 20.0),),
                        ),
                ),
    );
  }
}

class SecondPage extends StatelessWidget
{
        @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(

            appBar: AppBar(
                    title: Text('这是第二页'),
            ),
            body: Center(
                    child: RaisedButton(onPressed: (){
                          Navigator.pushNamed(context, '/first');
                    },child:Text('跳转到第二页',style: TextStyle(fontSize: 28.0),)),
            ),
    );
  }
}